home *** CD-ROM | disk | FTP | other *** search
- /*
- * Blob Manager Demonstration: Handlers for standard menus (those
- * that stick around all the time). Menus that exist only when
- * are particular window is in front are installed and removed by
- * the handler for that window.
- *
- * 12 July 1986 Paul DuBois
- */
-
-
- # include "TransSkel.h"
-
- # include "BlobMgr.h"
- # include "BlobDemo.h"
-
-
- static MenuHandle fileMenu;
- static MenuHandle editMenu;
- static MenuHandle windMenu;
-
-
- /*
- * wPtr is used to map Windows menu items onto the windows associated
- * with each item.
- */
-
- static WindowPtr wPtr[lastWindRes-firstWindRes];
- static short wCount = 0;
-
-
- static pascal void
- DoAbout (short item)
- {
- (void) SkelAlert (aboutAlrtRes, SkelDlogFilter (nil, true),
- skelPositionOnParentDevice);
- SkelRmveDlogFilter ();
- }
-
-
- /*
- * Close all the windows, from the back forward for better esthetics.
- */
-
- void
- CloseAllWindows (void)
- {
- WindowPeek w;
- WindowPtr lastVis;
-
- for (;;)
- {
- lastVis = (WindowPtr) nil;
- for (w = (WindowPeek) FrontWindow (); w != (WindowPeek) nil; w = w->nextWindow)
- {
- if (w->visible)
- lastVis = (WindowPtr) w;
- }
- if (lastVis == (WindowPtr) nil)
- break;
- SkelClose (lastVis);
- }
- }
-
-
- static pascal void
- DoFileMenu (short item)
- {
- Handle h;
-
- switch (item)
- {
- case closeWind:
- SkelClose (FrontWindow ());
- break;
- case closeAll:
- CloseAllWindows ();
- break;
- case getInfo:
- h = GetResource ('TEXT', helpTextRes);
- if (h != (Handle) nil)
- {
- HLock (h);
- TextDialog (textDlogRes, h, 0, 0, true);
- HUnlock (h);
- ReleaseResource (h);
- }
- break;
- case quit:
- SkelStopEventLoop (); /* tell SkelEventLoop () to quit */
- break;
- }
- }
-
-
- static pascal void
- DoEditMenu (short item)
- {
- (void) SystemEdit (item - 1); /* route to DA if appropriate */
- }
-
-
- /*
- * The Windows menu is used to select a given window and bring it
- * to the front. It also makes it visible if it wasn't already.
- */
-
- static pascal void
- DoWindMenu (short item)
- {
- SelectWindow (wPtr[item-1]);
- ShowWindow (wPtr[item-1]);
- }
-
-
- /*
- * Add title of each window to the Windows menu. Save the WindowPtr for
- * use later if the window is selected from the menu.
- */
-
- void
- AddWindowTitles (void)
- {
- WindowPeek theWind;
- Str255 title;
-
- theWind = (WindowPeek) FrontWindow ();
- while (theWind != (WindowPeek) nil)
- {
- GetWTitle ((WindowPtr) theWind, (StringPtr) &title);
- AppendMenu (windMenu, title);
- wPtr[wCount++] = (WindowPtr) theWind;
- theWind = theWind->nextWindow;
- }
- }
-
-
- /*
- * Clobber proc for menu handlers
- */
-
- pascal void
- DoMClobber (MenuHandle theMenu)
- {
- ReleaseResource ((Handle) theMenu);
- }
-
-
- /*
- * Menu hook, called when mouse is clicked in menu bar. Sets menu items
- * so they are enabled/disabled properly when Menu Manager shows them to
- * user.
- * - Enable File/Close Window if a window is visible, disable it otherwise.
- * - Enable File/Close All if a window is visible, disable it otherwise.
- * - Enable Edit menu items when a DA window is in front. Disable them
- * when a demo window is in front.
- * - In Windows menu, check the window that's frontmost, if any.
- */
-
- static pascal void
- MenuHookProc (void)
- {
- WindowPeek wPeek;
- short i;
-
- if ( (wPeek = (WindowPeek) FrontWindow ()) != (WindowPeek) nil)
- {
- EnableItem (fileMenu, closeWind);
- EnableItem (fileMenu, closeAll);
- }
- else
- {
- DisableItem (fileMenu, closeWind);
- DisableItem (fileMenu, closeAll);
- }
-
- if ( (wPeek = (WindowPeek) FrontWindow ()) != (WindowPeek) nil
- && wPeek->windowKind < 0) /* DA window in front */
- {
- EnableItem (editMenu, editUndo);
- EnableItem (editMenu, editCut);
- EnableItem (editMenu, editCopy);
- EnableItem (editMenu, editPaste);
- EnableItem (editMenu, editClear);
- }
- else /* DA not in front */
- {
- DisableItem (editMenu, editUndo);
- DisableItem (editMenu, editCut);
- DisableItem (editMenu, editCopy);
- DisableItem (editMenu, editPaste);
- DisableItem (editMenu, editClear);
- }
-
- for (i = 0; i < wCount; i++)
- {
- if (FrontWindow () == wPtr[i])
- SetItemMark (windMenu, i+1, checkMark);
- else
- SetItemMark (windMenu, i+1, noMark);
- }
- }
-
-
- /*
- * Set up menus: Tell TransSkel to make a default Apple menu handler,
- * create handlers for the File, Edit and Windows menus. Install menu
- * hook to enable/disable menu items.
- *
- * \311 is the ellipsis character.
- */
-
- void
- SetupMenus (void)
- {
- SkelApple ("\pAbout BlobMgr Demo\311", DoAbout);
- fileMenu = GetMenu (fileMenuRes);
- SkelMenu (fileMenu, DoFileMenu, DoMClobber, false, false);
- editMenu = GetMenu (editMenuRes);
- SkelMenu (editMenu, DoEditMenu, DoMClobber, false, false);
- windMenu = GetMenu (windMenuRes);
- SkelMenu (windMenu, DoWindMenu, DoMClobber, false, true);
- SkelSetMenuHook (MenuHookProc);
- }
-